package br.com.imob.view;

import javax.faces.bean.ManagedBean;

import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

import br.com.imob.modelo.Cidade;

@ManagedBean
@RequestScoped
public class ConvertObject implements Converter {

	public Object getAsObject(FacesContext context, UIComponent component, String value) {
		Cidade city = new Cidade();
		if (!"".equals(value)) {
			try {
				city.setCidade(value);
			} catch (Throwable ex) {
				// ResourceBundle bundle = ResourceBundle.getBundle("messages");
				// FacesMessage msg = new
				// FacesMessage("faculty_convertion_message");
				// msg.setSeverity(FacesMessage.SEVERITY_ERROR);
				throw new ConverterException();
			}
		}
		return city;
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component, Object value) {

		String val = null;

		if (!"".equals(value)) {
			try {
				val = value.toString();
			} catch (Throwable ex) {
				// ResourceBundle bundle = ResourceBundle.getBundle("messages");
				// FacesMessage msg = new
				// FacesMessage(bundle.getString("faculty_convertion_message"));
				// msg.setSeverity(FacesMessage.SEVERITY_ERROR);
				// throw new ConverterException(msg);
				System.out.println(ex.getMessage());
				ex.printStackTrace();
			}
		}
		return val;
	}

}
